// var timer = setInterval(function () {
//     window.scrollBy(0, 5);
//     if (0) {
//         clearInterval(timer);
//     }
// }, 500);

console.log("已经注入");


chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
    var screenHeight = window.screen.availHeight - 130;
    console.log('屏幕高度:' + screenHeight);
    if (request.cBox == true) {
        console.log('自动翻页开始');
    } else {
        console.log('自动翻页停止');
    }
    // console.log('request.time' + request.time);
    if(request.time < 0.1){
        request.time = 20;
    }
    if(request.model_box == true){
        if (request.cBox == true) {
            tuntun_timer = setInterval(function () {
                
                window.scrollBy(0, screenHeight);
            }, request.time);
        }
        if (request.cBox == false) {
            clearInterval(tuntun_timer);
        }
        sendResponse('我收到了你的消息！');

    }
    else{
        if (request.cBox == true) {
            tuntun_timer = setInterval(function () {
                
                window.scrollBy(0, 5);
            }, request.time);
        }
        if (request.cBox == false) {
            clearInterval(tuntun_timer);
        }
        sendResponse('我收到了你的消息！');
    }
});


if (cBox == true) {
    chrome.runtime.sendMessage({greeting: 1}, function(response) {
        console.log('收到来自后台的回复：' + response);
    });
}
